package com.ikas.ai.framework.node.impl;

import com.alibaba.fastjson.JSONObject;
import com.ikas.ai.framework.core.model.NodeInputVariables;
import com.ikas.ai.framework.flow.ScoreFlow;
import com.ikas.ai.framework.node.NodeType;

import java.util.function.Supplier;

/**
 * @Description: 数据节点
 * @Author: qi.yilai
 * @Date: 2023/1/12 16:57
 * @Version: 1.0.0
 **/
public class DataNode extends AbstractNode<JSONObject> {
    private Supplier<JSONObject> supplier;

    public DataNode(ScoreFlow scoreFlow, Supplier<JSONObject> supplier, Long nodeId, Long nodeInstanceId, String name) {
        super(scoreFlow, nodeId, nodeInstanceId, name);
        this.supplier = supplier;
    }

    @Override
    public synchronized void input(NodeInputVariables nodeInputVariables) {
        throw new UnsupportedOperationException("数据节点不支持输入操作");
    }

    @Override
    JSONObject doExecute() {
        return supplier.get();
    }


    @Override
    public NodeType type() {
        return NodeType.DATA;
    }
}
